const app = getApp();
Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#00B968",
    list: [{
      "pagePath": "/pages/index/index",
      "iconPath": "/images/indexIcon/tbindex.png",
      "selectedIconPath": "/images/indexIcon/tbindexs.png",
      "text": "首页",
      id: 0
    }, 
    
    {
      "pagePath": "/pages/shengyi/shengyi",
      "text": "生意",
      "iconPath": "/images/indexIcon/tabbar_PM@3x.png",
      "selectedIconPath": "/images/indexIcon/tabbar_PMS@3x.png",
      id: 1
    },
    
     {
      "pagePath": "/pages/releaseIndex/releaseIndex",
      "text": "",
      "iconPath": "/images/home/tabbar_center.png",
      "selectedIconPath": "/images/home/tabbar_center.png",
      id: 2
    }, /*{
      "pagePath": "/pages/zhaobiaogonggao/index",
      "text": "招标拍卖",
      "iconPath": "/images/indexIcon/tabbar_PM@3x.png",
      "selectedIconPath": "/images/indexIcon/tabbar_PMS@3x.png",
      id: 3
    },*/
    {
      "pagePath": "/pages/dingyue/index",
      "iconPath": "/images/indexIcon/tbdingyue.png",
      "selectedIconPath": "/images/indexIcon/tbdingyues.png",
      "text": "订阅",
      id: 3
    },
    {
      "pagePath": "/pages/user/index",
      "text": "我的",
      "iconPath": "/images/indexIcon/tbmy.png",
      "selectedIconPath": "/images/indexIcon/tbmys.png",
      id: 4
    }],
    isSafeBottom: true,// 是否有底部安全距离,默认有
    isShowIcon: false // 默认不显示icon

  },

  lifetimes: {
    created: function (params) {
      
    },
    attached: function (params) {
      let sysinfo = wx.getWindowInfo()
      let safeH = sysinfo.screenHeight - sysinfo.safeArea.bottom
      this.setData({
        isSafeBottom: safeH <= 0 ? false : true
      })
    }
  },
  attached() {
  },

  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      if (app.checkFjLogin() == false && data.index==1) {
        wx.navigateTo({ url: '/pages/login/index' });
        return
      }
      wx.switchTab({ url })
      this.setData({
        selected: data.index
      })
      this.isHaveSafeBottom()
      // this.getTabsBage()
    },
    // 获取生意角标
    getTabsBage() {
      if (app.checkFjLogin()) {
        let parame = {
          loginuid: wx.getStorageSync('FjLoginLog').UID,
        }
        app.getDaoPostSearchNew('api/FeijiuApp/Feijiu_Get_Business_GetNum_v2024', parame, (item) => {
          if (item.code == 200) {
            let dataDic = item['data']
            if (dataDic.dxnum == 0 && dataDic.zcnum == 0 && dataDic.pmnum == 0) {
              this.setData({
                isShowIcon: false
              })
            }else {
              this.setData({
                isShowIcon: true
              })
            }
            console.log('isShowIconp-', this.data.isShowIcon)
          } 
          wx.hideLoading()
        })
      }
    },

    // 检查是否有底部安全距离
    isHaveSafeBottom() {
      let sysinfo = wx.getWindowInfo()
      let safeH = sysinfo.screenHeight - sysinfo.safeArea.bottom
      this.setData({
        isSafeBottom: safeH <= 0 ? false : true
      })
    }
  }
})